package com.teacher.hong.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;

import java.io.IOException;


/**
 * 根据IP进行过滤
 */
//@WebFilter("/*")
public class IPFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    //黑名单IP数组
    String[] blackIPs = {"192.168.1.2", "192.168.1.5"};

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("这里我们可以进行IP过滤");
        /*
        if (IP属于黑名单) {
            输出一些提示信息
            return;
        }
         */
        //放行，将servletRequest, servletResponse俩对象传递给下一个过滤器
        servletRequest.setAttribute("name", "jack");
        filterChain.doFilter(servletRequest, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
